<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="password" id="pwd">
    <button id="btn">显示</button>

    <script>
        var pwd = document.getElementById('pwd');
        var btn = document.getElementById('btn');
        
        flag = 0;
        btn.onclick = function () {
            if (flag == 0) {
                pwd.type = 'text';
                btn.innerHTML = '隐藏';
                flag=1;
            }else{
                pwd.type = 'password';
                btn.innerHTML = '显示';
                flag=0;
            }


        }


    </script>
</body>

</html>